//
//  YearView.swift
//  StoreProject
//
//  Created by CYC on 2021/9/28.
//

import UIKit

class YearView: UIView {
    
    var model = YearModel()
    
    var label1 = UILabel()  // 年
    var label2 = UILabel()  // 辛丑牛年
    var label3 = UILabel()  // 农历初一

    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        fatalError("")
    }
    
    
    // MARK:创建UI
    func creatUIAction(model: YearModel) {
        
        self.model = model
        self.removeAllSubviews()
        
        let line1 = UIView.init(frame: CGRect.init(x: 0, y: self.c_height() - kLineSize, width: self.c_width(), height: kLineSize))
        line1.backgroundColor = kLineColor
        self.addSubview(line1)
        
        
        let BH = CGFloat(15)
        let BW = CGFloat(60)
        let lab1 = UILabel.init(frame: CGRect.init(x: self.c_width() - BW, y: self.c_height() - 5 - BH, width: BW, height: BH))
        lab1.textColor = kLabelColor2
        lab1.textAlignment = .left
        lab1.font = kRFont(10)
        lab1.text = "农历初一"
        self.addSubview(lab1)
        self.label3 = lab1
        
        let line2 = UIView.init(frame: CGRect.init(x: lab1.c_left() - 15, y: lab1.c_top() + (lab1.c_height() - kLineSize)/2.0, width: 10, height: kLineSize))
        line2.backgroundColor = kMainColor
        self.addSubview(line2)
        
        let lab2 = UILabel.init(frame: CGRect.init(x: lab1.c_left(), y: lab1.c_top() - BH, width: BW, height: BH))
        lab2.textColor = kLabelColor2
        lab2.textAlignment = .left
        lab2.font = kRFont(10)
        lab2.text = model.chineseYear
        self.addSubview(lab2)
        self.label2 = lab2
        
        let line3 = UIView.init(frame: CGRect.init(x: lab2.c_left() - 15, y: lab2.c_top() + (lab2.c_height() - kLineSize*2)/2.0, width: 10, height: kLineSize*2))
        line3.backgroundColor = kMainColor
        self.addSubview(line3)
        
        let lab3 = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: lab1.c_left(), height: self.c_height()))
        lab3.textAlignment = .left
        lab3.font = kBFont(30)
        lab3.text = String.init(format: "%d年", model.year)
        self.addSubview(lab3)
        self.label1 = lab3
        
        // 今天
        if model.year == kTodayCom.year {
            
            lab3.textColor = kMainColor
        } else {
            
            lab3.textColor = kLabelColor1
        }
        
    }
}
